<?php
	include_once "dataservice.php";
	
	class thichbaiviet_db
	{
		public function Them($MaBaiViet, $MaNguoiDung, $ThoiGian)
		{
			$sql = "INSERT INTO `tbl_thichbaiviet`(`MaBaiViet`, `MaNguoiDung`, `ThoiGian`) 
					VALUES ('$MaBaiViet', '$MaNguoiDung', '$ThoiGian')";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		public function CapNhat($MaBaiViet, $MaNguoiDung, $ThoiGian)
		{
			$sql = "UPDATE `tbl_thichbaiviet` 
					SET `MaNguoiDung`='$MaNguoiDung',`ThoiGian`='$ThoiGian' 
					WHERE `MaBaiViet`='$MaBaiViet'";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		public function Xoa($MaBaiViet, $MaNguoiDung)
		{
			$sql = "DELETE FROM `tbl_thichbaiviet` 
					WHERE `MaNguoiDung`='$MaNguoiDung' AND `MaBaiViet`='$MaBaiViet'";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		//Lấy danh sách các lượt thích của bài viết hiện tại
		public function LayDanhSach($MaBaiViet)
		{
			$sql = "SELECT * FROM `tbl_thichbaiviet` WHERE 1";
			
			if($MaBaiViet != 0)
				$sql .= " AND MaBaiViet = '$MaBaiViet'";
			
			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}
	}
?>